<?php
/**
 * @copyright	Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * View class for a list of users.
 *
 * @package		Joomla.Administrator
 * @subpackage	com_users
 * @since		1.6
 */
class UsersViewUsers extends JViewLegacy
{
	protected $items;
	protected $pagination;
	protected $state;
    protected $prefs;
    
	/**
	 * Display the view
	 */
	public function display($tpl = null)
	{
        $filters = array(
            'type'  =>JRequest::getVar('user_type','all'),
            'pref'  =>JRequest::getVar('pref','all'),
            'ocba_name'  =>JRequest::getVar('ocba_name',''),
            'ocba_code'  =>JRequest::getVar('ocba_code',''),
        );
        
        /* permission */
        $aut = new bgAuthorize();
        if($aut->checkEditOwn()){
            $filters['user_id'] = $aut->getUserID();
            $this->items = $this->getModel()->getItems($filters);
            $this->checkEO = true;
        }else{
            $this->items = $this->getModel()->getItems($filters);
            $this->checkEO = false;
        }
        $this->prefs = $this->getModel()->getPrefs();
		$this->pagination	= $this->get('Pagination');
		$this->state		= $this->get('State');

		if (count($errors = $this->get('Errors'))) {
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}

		// Include the component HTML helpers.
		JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

		$this->addToolbar();
		parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	protected function addToolbar()
	{
		$canDo	= UsersHelper::getActions();
        JToolBarHelper::title(JText::_('ユーザー管理'), 'user');
        
        /* permission */
        $aut = new bgAuthorize();
        if($aut->checkAdd()){
            JToolBarHelper::addNew('user.add','作成');
        }
        JToolBarHelper::editList('user.edit','編集');
        if($aut->checkDelete()){
            JToolBarHelper::deleteList('', 'users.delete','削除');
        }
        
        //JToolBarHelper::preferences('com_users');

	}
}
